﻿<m:ElevatorAutomaton 
    x:Class="Rhizome.QuickStart.Elevator.Model.Automaton" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:m="clr-namespace:Rhizome.QuickStart.Elevator.Model" 
	xmlns:r="clr-namespace:Rhizome.Model;assembly=Rhizome.Core" 
	InitialState="Main" 
    >
	
	<m:ElevatorState Id="Main">

		<m:Stop />

		<m:ElevatorAutomaton InitialState="Working" >

			<m:ElevatorAutomaton.Edges>

				<r:Edge State="Working">
					<r:Transition Event="Break" State="Broken" />
				</r:Edge>

				<r:Edge State="Broken">
					<r:Transition Event="Repeared" State="Working" />
				</r:Edge>

			</m:ElevatorAutomaton.Edges>

			<m:ElevatorState Id="Working">

				<r:OnEntry Action="WorkTime=0" />

				<m:Door />
				<m:UpDown />

				<r:Counter Property="WorkTime" Period="00:00:01" Step="1" />
				<r:Trigger Property="WorkTime" Criterion="WorkTime = 15" Action="CastEvent Break" />

			</m:ElevatorState>

			<m:ElevatorState Id="Broken">
				
				<r:OnEntry Action="WorkTime=0" />

				<r:Counter Property="WorkTime" Period="00:00:01" Step="-1" />
				<r:Trigger Property="WorkTime" Criterion="WorkTime = -10" Action="CastEvent Repeared" />

				<r:OnMessage Message="Stopped" MessageCriterion="Data == 1" Action="CastEvent Repeared" />

			</m:ElevatorState>

		</m:ElevatorAutomaton>

	</m:ElevatorState>

</m:ElevatorAutomaton>